<?php
namespace Common\Common;

abstract class Model extends  \Think\Model{
    protected $objectClass;
    /**
     * 通过主键获取对象
     * @return Model
     */
    public function fetch(){
        $args = func_get_args();
        if(is_string($this->tablePrimary))
            $this->tablePrimary = [$this->tablePrimary];
        $condition = [];
        foreach ($this->tablePrimary as $key => $value)
            $condition[$value] = $args[$key];
        $data = $this->where($condition)->find();
        $className = substr(static::class, 0, -5);
        $className = $className.'Object';
        return new $className($data, $this);
    }
    /**
     * 通过主键获取对象
     * @return array
     */
    public function fetchList($condition){
        $dataList=$this->where($condition)->select();
        $result=[];
        $className = substr(static::class, 0, -5);
        $className = $className.'Object';
        foreach($dataList as $value){
            $result[]=new $className($value,$this);
        }
        return $result;
    }



}